package cool.doudou.doudada.wechat.core.helper;

import cool.doudou.doudada.wechat.core.Constant;
import cool.doudou.doudada.wechat.core.factory.TokenMapFactory;
import cool.doudou.doudada.wechat.properties.WechatProperties;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * TokenHelper
 *
 * @author jiangcs
 * @since 2022/08/23
 */
public class TokenHelper {
    private WechatProperties wechatProperties;

    public String accessToken() {
        return accessToken(wechatProperties.getCredentials().get(0).getAppId());
    }

    public String accessToken(String appId) {
        return TokenMapFactory.get(Constant.KEY_ACCESS_TOKEN + appId);
    }

    public String jsApiTicket() {
        return jsApiTicket(wechatProperties.getCredentials().get(0).getAppId());
    }

    public String jsApiTicket(String appId) {
        return TokenMapFactory.get(Constant.KEY_JS_API_TICKET + appId);
    }

    @Autowired
    public void setWechatProperties(WechatProperties wechatProperties) {
        this.wechatProperties = wechatProperties;
    }
}
